﻿using System;
using System.Collections.Generic;
using System.Text;
using Keyki.NefClass.Kernel.Data;

namespace Keyki.NefClass.Kernel.Fuzzy.Rulles
{
	public sealed class FuzzyRule
	{
		public Antecedent Antecedent { get; set; }

		public FuzzyRule(int classId)
		{
			Class = classId;
		}//FuzzyRule

		public int Class { get; private set; }

		public double Performance { get; set; }

		public double Compute(DataSample value)
		{
			return Antecedent.Compute(value);
		}//Compute

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder("IF ");

			for (int i = 0; i < Antecedent.Count; i++)
			{
				var pair = Antecedent[i];
				stringBuilder.Append("X" + i + " is " + pair.Name + " ");
			}

			stringBuilder.Append("THEN " + Core.NefClass.GetClassName(Class));

			return stringBuilder.ToString();
		}

		public static bool operator> (FuzzyRule fuzzyRule1, FuzzyRule fuzzyRule2)
		{
			return fuzzyRule1.Class > fuzzyRule2.Class;
		}

		public static bool operator <(FuzzyRule fuzzyRule1, FuzzyRule fuzzyRule2)
		{
			return fuzzyRule1.Class < fuzzyRule2.Class;
		}

		public static int CompareRuleByClass(FuzzyRule fuzzyRule1, FuzzyRule fuzzyRule2)
		{
			return fuzzyRule1.Class.CompareTo(fuzzyRule2.Class);
		}
	}//FuzzyRule
}//Keyki.NefClass.Kernel.Fuzzy